#ifndef __EDITORSCENEMGR_H__
#define __EDITORSCENEMGR_H__

#include <stl/string.h>
#include <standard/reference.h>
#include <standard/texturetarget.h>
#include <standard/xml.h>
#include <standard/gui.h>
#include <standard/raycaster.h>
#include <bigimage/orbitcontrols.h>
#include "global.h"

struct STerrainSelectedPosInfo{
    float m_vPos[3];
    int32 m_nCellX, m_nCellY;
};

class CTerrainObject;
class CEditorScene;
class CTerrainGridHelperObject;
class CSceneObjectConfigManager;
class CEditorSceneMgr: public CRefObject{
public:
    CEditorSceneMgr();
    virtual ~CEditorSceneMgr();
    void Init( CTextureTarget* pTarget, float fViewportWidth, float fViewportHeight, const char* strResourceSpace, int32 nBlockCountX, int32 nBlockCountY, float fBlockSize, float fObjectUnitSize, const char* strSkyBox );
    void Final();
    bool32 Open( CTextureTarget* pTarget, float fViewportWidth, float fViewportHeight, CXML* pXML );
    bool32 Save( const char* strFileName );
    void Update( int32 nDelta, float fDelta );
    void Render();
    void OnMouseEvent( EUIMouseMessage eMouseMessage, int32 x, int32 y, int32 z, int32 s);
    void OnKeyEvent( EUIKeyMessage eKeyMessage, int32 nKey);
    class CTerrainBlock* GetSelectBlock( int32 x, int32 y, STerrainSelectedPosInfo* pSelectedPosInfo );
    void SetLayerTexture( int32 nCellX, int32 nCellY, const char* strTextureFile, int32 nBrushType, int32 nBrushSize, int32 nBrushAlpha );
    void SetLayerTextureInfo( int32 nCellX, int32 nCellY, CTexture* pTextureObj, int32 nBrushAlpha );

    void SetOperator( EOperatorType eOperatorType );
    CRaycaster* CEditorSceneMgr::BuildMouseRaycaster( CRaycaster* pRaycaster, int32 x, int32 y );
    CSceneObjectConfigManager* GetSceneObjectCfgMgr(){ return m_rSceneObjectCfgMgr.GetEntityData(); }
    const char* GetResourceSpace(){ return m_strResourceSpace.c_str(); }
    CTerrainObject* GetTerrainObject(){ return m_rTerrainObject.GetEntityData(); }
    CEditorScene* GetScene(){ return m_rEditorScene.GetEntityData(); }
    class CCommandMgr* GetCommandMgr(){ return m_rCommandMgr.GetEntityData(); }
    class CSceneObjectManager* GetSceneObjectMgr(){ return m_rSceneObjectManager.GetEntityData(); }
    class CSceneObjectNavigationMap* GetSceneObjectNavigationMap(){ return m_rSceneObjectNavigationMap.GetEntityData(); }
    float GetTerrainHeight( float x, float y );
    void SetVisibled( int32 nType, bool32 bVisibled );
    void SetSceneVisibleMode( int32 nMode );

private:
    CTextureTarget* m_pTextureTarget;
    float m_fWidth, m_fHeight;

    Ref<CCamera*> m_rCamera;
    Ref<COrbitControls*> m_rCameraControls;

    string32 m_strResourceSpace;

    Ref<class COperator*> m_rCurOperator;

    Ref<class CCommandMgr*>m_rCommandMgr;


    Ref<CTerrainObject*>m_rTerrainObject;
    Ref<CTerrainGridHelperObject*> m_rTerrainGridHelperObject;

    Ref<CEditorScene*> m_rEditorScene;

    Ref<class CSceneObjectNavigationMap*> m_rSceneObjectNavigationMap;
    Ref<class CNavigateionHelperObject*> m_rNavigateionHelperObject;
    

    Ref<class CSceneObjectManager*>m_rSceneObjectManager;

    

private:
    Ref<CSceneObjectConfigManager*> m_rSceneObjectCfgMgr;
};

#endif
